#include "Logger.hpp"
#include <stdio.h>
#include <string.h>
#include <stdint.h>

static char _text_logger_fmt_buffer[128] = {0};

/* About text logger. */

TextLogger::TextLogger(TextLogger::Portable *portable){
    this->portable = portable;
}

void TextLogger::notice(char *message){
    sprintf(_text_logger_fmt_buffer,"[NOTICE]%s\r\n",message);
    int len = strlen(_text_logger_fmt_buffer);
    this->portable->write(_text_logger_fmt_buffer,len);
}

void TextLogger::warning(char *message){
    sprintf(_text_logger_fmt_buffer,"[WARNING]%s\r\n",message);
    int len = strlen(_text_logger_fmt_buffer);
    this->portable->write(_text_logger_fmt_buffer,len);
}

void TextLogger::alert(char *message){
    sprintf(_text_logger_fmt_buffer,"[ALERT]%s\r\n",message);
    int len = strlen(_text_logger_fmt_buffer);
    this->portable->write(_text_logger_fmt_buffer,len);
}

void TextLogger::error(int err_code){
    sprintf(_text_logger_fmt_buffer,"[ERROR]Error occured. Error Code:%d\r\n",err_code);
    int len = strlen(_text_logger_fmt_buffer);
    this->portable->write(_text_logger_fmt_buffer,len);
}

/* About binary logger. */

BinaryLogger::BinaryLogger(BinaryLogger::Portable *portable){
    this->portable = portable;
}

void BinaryLogger::notice(char *message){
    return;
}


void BinaryLogger::warning(char *message){
    return;
}

void BinaryLogger::alert(char *message){
    return;
}

void BinaryLogger::error(int err_code){
    static uint32_t count = 0;
    /* Read log count. */
    this->portable->read(&count,0,sizeof(count));
    /* Write to the next position. */
    this->portable->write(&err_code,count * sizeof(int) + sizeof(count),sizeof(int));
    count++;
    this->portable->write(&count,0,sizeof(count));
    return;
}